<?php
/**
 * [weliam] Copyright (c) 2016/3/23
 * order.ctrl
 * 订单控制器
 */
$cs_start_time = time();
defined('IN_IA') or exit('Access Denied');
wl_load()->model('order');
wl_load()->model('goods');
wl_load()->model('merchant');
wl_load()->model('functions');
wl_load()->model('judgment');
wl_load()->classs('qrcode');
$op = !empty($_GPC['op']) ? $_GPC['op'] : 'list';
$pagetitle = '我的订单';

if($op =='list'){
	$status = ($_GPC['status']!='')?$_GPC['status']:'';

	include wl_template('myorder');
}

if($op =='ajax'){
	$page = $_GPC['page'];
	$pagesize = $_GPC['pagesize'];
	$status = $_GPC['status'];
	$servestype = 1;
	$data = order_get_list(array('openid'=>$_W['openid'],'usepage'=>1,'page'=>$page,'pagesize'=>$pagesize,'status'=>$status));
	foreach($data['list'] as $key =>&$vlaue){
		switch($vlaue['status']){
			case 0:$statusname='待付款';break;
			case 1:$statusname='已付款';break;
			case 2:$statusname='待收货';break;
			case 3:$statusname='已完成';break;
			case 4:$statusname='已退款';break;
			case 5:$statusname='强退款';break;
			case 6:$statusname='部分退款';break;
			case 7:$statusname='已退款';break;
			case 8:$statusname='待使用';break;
			case 9:$statusname='已取消';break;
			case 10:$statusname='待退款';break;
			default:$statusname='待付款';
		}
		$time = time();
		$endtime = $goods['endtime'];
		$createqrcode =  new creat_qrcode();
		$createqrcode->creategroupQrcode($vlaue['orderno']);
		if($vlaue['status']==8&&$vlaue['is_hexiao']!=0){

			$statusname='到店自提';
		}
		if($vlaue['g_id']>0){
			$goods = goods_get_by_params(" id = {$vlaue['g_id']} ");
			$vlaue['gimg'] = $goods['share_image'];
			$vlaue['name'] = $vlaue['goodsname'];
			if(empty($vlaue['name']))
			{
				$vlaue['name']='数据已删除';
			}
			$vlaue['selltype'] = $goods['selltype'];
			if($vlaue['status']==0)
			{
				$count_order=pdo_fetchall('select id from cm_tg_order where tuan_id=:tuan_id and openid=:openid and status in (1,2,3,7,8,10)',array(':tuan_id'=>$vlaue['tuan_id'],':openid'=>$_W['openid']));
				if(!empty($count_order))
				{
					pdo_update('tg_order',array('status'=>9),array('orderno'=>$value['orderno']));
					$vlaue['status']=9;
					$statusname='已取消';
				}

			}
		}else{
		$vlaue['name']=$vlaue['orderno'];
		$vlaue['gimg'] = tomedia($config['share']['share_image']);
		$vlaue['goods']=pdo_fetchall("select * from ".tablename('tg_collect')." where  orderno=:orderno",array('orderno'=>$vlaue['orderno']));
			foreach($vlaue['goods'] as $k =>&$v){
				$gs=pdo_fetch("select * from ".tablename('tg_goods')." where  id=:id",array('id'=>$v['sid']));
				$v['gname']=$v['goodsname'];
			}
		}
		$vlaue['service']=0;
		if($vlaue['status'] == 1 || $vlaue['status'] == 2 || $vlaue['status'] == 3|| $vlaue['status'] == 6|| $vlaue['status'] == 8){
		$vlaue['service']=$config['base']['service'];
		}
		if($vlaue['servestype'] >0)
		{
			$vlaue['service']=$config['base']['service'];
		}
		$vlaue['ga'] = $goods['a'];
		$vlaue['statusname'] = $statusname;
		if($vlaue['status'] != 5 && $vlaue['status'] != 0 && $vlaue['is_tuan'] == 1){
			$vlaue['ta'] = app_url('order/group')."&tuan_id=".$vlaue['tuan_id'];
		}
		$vlaue['sa'] = app_url('order/serves')."&id=".$vlaue['id'];
		if($vlaue['merchantid']){
			$merchant = merchant_get_by_id($vlaue['merchantid']);
			$vlaue['merchant_name'] = $merchant['name'];
		}else{
			$vlaue['merchant_name'] = $_W['account']['name'];
		}
        if($goods['hasoption']==1){
		if ($vlaue['optionid']>0) {
			$option = pdo_fetch("select title,productprice,marketprice,stock,weight from" . tablename("tg_goods_option") . " where id=:id limit 1", array(":id" => $vlaue['optionid']));
		}
		//$vlaue['optionname'] = $option['title'];

	}

	}
	die(json_encode($data));
}

if($op =='detail'){
	$id = intval($_GPC['id']);
	if($id){
		$order = order_get_by_id($id);

		$sto=pdo_fetch("select * from".tablename('tg_store')."where id ='{$order['comadd']}' and uniacid='{$_W['uniacid']}'");
		if($order['is_hexiao']==1){

			//门店信息
			$storesids = explode(",", $order['storeid']);
			foreach($storesids as$key=>$value){
				if($value){
					$stores[$key] =  pdo_fetch("select * from".tablename('tg_store')."where id ='{$value}' and uniacid='{$_W['uniacid']}'");
				}
			}
		}
		$sal=pdo_fetch("select * from" . tablename('tg_member') . " where from_user ='".$order['veropenid']."'");
	}
	/*
	$new_endtime = date('Y-m-d H:i:s',$order['gettime']);
	$over_endtime = strtotime("$new_endtime +15 day");
	$now_time = time();
	if($now_time >= $over_endtime){
		$notshow=1;
	}
	if($order['status']==0||$order['status']==1||$order['status']==8||$order['status']==4||$order['status']==5||$order['status']==6||$order['status']==7||$order['status']==9)
	{
		$notshow=1;
	}
	*/
	include wl_template('myorder_detail');
}
if ($op == 'detail-notice') {
	$id = intval($_GPC['id']);
	$judgments = getJudgments($id);
	include wl_template('myorder_detail_notice');
}

if($op =='cancel'){
	$orderno = $_GPC['orderno'];
	if($orderno){
		$order = order_update_by_params(array('status' => 9),array('orderno' => $orderno));
//        file_put_contents(TG_DATA."aa.log", var_export($order, true).PHP_EOL, FILE_APPEND);
//		die(json_encode(array('order' => $order)));
		if($order){
			//$item = pdo_fetch("SELECT * FROM " . tablename('tg_order') . " WHERE orderno = :orderno", array(':orderno' => $orderno));
			//$goods = goods_get_by_params(" id={$item['g_id']} ");
			//cancelorder($_W['openid'], $item['price'], $goods['gname'], $orderno, '');
			wl_json(1);
		}else{
			wl_json(0,'取消订单失败！');
		}
	}else{
		wl_json(0,'缺少订单号');
	}
}
if($op =='tip'){
	$list = pdo_fetchall("SELECT openid FROM ".tablename('tg_order')." WHERE uniacid = {$_W['uniacid']} AND status in(1,2,3,8,6) AND openid<>'' and mobile<>'虚拟' order by ptime desc limit 10");
	$arr=array();
	foreach($list as $key =>&$vlaue){
	$sql = 'SELECT nickname,avatar FROM '.tablename('tg_member').' WHERE openid=:openid and uniacid=:uniacid';
	$paramse = array(':openid'=>$vlaue['openid'], ':uniacid'=>$_W['uniacid']);
	$members = pdo_fetch($sql, $paramse);
	$vlaue['nickname'] = mb_substr($members['nickname'], 0,3,'utf-8');
	$vlaue['avatar'] = $members['avatar'];
	$citylist = pdo_fetch("select city from ".tablename('tg_address')." where uniacid = {$_W['uniacid']} and openid='{$vlaue['openid']}'");
	if(!empty($citylist['city']))
	{
		$vlaue['city'] = $citylist['city'];
	}


	$sec = rand(1,20);
	$vlaue['sec'] = $sec;
	}
	die(json_encode($list));
}
if($op =='topay'){
	$orderno = $_GPC['orderno'];
	if($orderno){
		$order = order_get_by_params(" orderno = '{$orderno}' ");
		if($order['status'] == 0){

			wl_json(1);
		}else{
			wl_json(0,'订单状态错误');
		}
	}else{
		wl_json(0,'缺少订单号');
	}
}

if($op =='receipt'){
	$orderno = $_GPC['orderno'];

	if($orderno){

		//佣金
		$value = pdo_fetch("select * from".tablename('tg_order')."where  uniacid='{$_W['uniacid']}' and id='{$orderno}'");
		if(intval($value['comtype'])==0&&$value['status']==2)
		{
					/**********************/
					//积分
			if($value['g_id']>0){
						$goodsInfo = pdo_fetch("SELECT * FROM " . tablename('tg_goods') . " WHERE uniacid ='{$_W['uniacid']}' and id = '{$value['g_id']}'");
						$fans = pdo_fetch("SELECT * FROM " . tablename('mc_mapping_fans') . " WHERE uniacid ='{$_W['uniacid']}' and openid = '{$value['openid']}'");
						$mencredit=pdo_fetch("SELECT * FROM " . tablename('mc_members') . " WHERE uniacid ='{$_W['uniacid']}' and uid = '{$fans['uid']}'");
						$creditnum=$mencredit['credit1']+$goodsInfo['credit'];
						pdo_update('mc_members',array('credit1'=>$creditnum),array('uid'=>$fans['uid']));
						//佣金
					$ud = pdo_fetch("select parentid from".tablename('tg_member')."where  uniacid='{$_W['uniacid']}' and from_user='{$value['openid']}'");
					if(intval($ud['parentid'])>0)
					{
					$parent=pdo_fetch("select * from".tablename('tg_member')."where  uniacid='{$_W['uniacid']}' and id={$ud['parentid']}");
					if($value['commissiontype']==2)
					{
						$price1=$value['commission'];
					}
					else{
					$price1=($value['price']-$value['cost_fee'])*$value['commission']/100;//佣金计算
						}
					$billing=$parent['billing']+$price1;//已结算佣金
					$wallet=$parent['wallet']+$price1;//钱包总佣金
					//$nobilling=$parent['nobilling']-$price;//未结算佣金
					pdo_update('tg_member',array('billing'=>$billing,'wallet'=>$wallet),array('id'=>$parent['id']));
					//佣金结算记录
					$bdata = array(
					'uniacid' => $_W['uniacid'],
					'openid' => $parent['from_user'],
					'orderno' => $value['orderno'],
					'billdate' => TIMESTAMP,
					'price' => $price1
					);
					pdo_insert('tg_billrecord', $bdata);
					pdo_update('tg_order',array('comtype'=>1),array('id'=>$value['id']));
					}
//
			}
			if($value['g_id']==0)
			{

				$favoriteqqq = pdo_fetchall("SELECT * FROM " . tablename('tg_collect') . " WHERE uniacid ='{$_W['uniacid']}'   and orderno='{$value['orderno']}'");
				$fans = pdo_fetch("SELECT * FROM " . tablename('mc_mapping_fans') . " WHERE uniacid ='{$_W['uniacid']}' and openid = '{$_W['openid']}'");
				$mencredit=pdo_fetch("SELECT * FROM " . tablename('mc_members') . " WHERE uniacid ='{$_W['uniacid']}' and uid = '{$fans['uid']}'");
				$creditnum=$mencredit['credit1']+$goodsInfo['credit'];
				$price1=0;
				foreach ($favoriteqqq as $key => $orderss)
					{
						$gs= pdo_fetch("select * from ".tablename('tg_goods')."where uniacid='{$_W['uniacid']}' and id={$orderss['sid']} ");
						if(!empty($gs['credit'])&&$gs['credit']!=0)
						{
							$creditnum+=$gs['credit']*$orderss['num'];
						}
					if($gs['commissiontype']==2){$price1+=$gs['commission'];}
					     else{
							 $price1+=($orderss['oprice']*$orderss['num'])*$orderss['commission']/100;//佣金计算
						 }
					}
					pdo_update('mc_members',array('credit1'=>$creditnum),array('uid'=>$fans['uid']));
				//积分
				//佣金
					$ud = pdo_fetch("select parentid from".tablename('tg_member')."where  uniacid='{$_W['uniacid']}' and from_user='{$value['openid']}'");
					if(intval($ud['parentid'])>0)
					{
					$parent=pdo_fetch("select * from".tablename('tg_member')."where  uniacid='{$_W['uniacid']}' and id={$ud['parentid']}");

					$billing=$parent['billing']+$price1;//已结算佣金
					$wallet=$parent['wallet']+$price1;//钱包总佣金
					//$nobilling=$parent['nobilling']-$price;//未结算佣金
					pdo_update('tg_member',array('billing'=>$billing,'wallet'=>$wallet),array('id'=>$parent['id']));
					//佣金结算记录
					$bdata = array(
					'uniacid' => $_W['uniacid'],
					'openid' => $parent['from_user'],
					'orderno' => $value['orderno'],
					'billdate' => TIMESTAMP,
					'price' => $price1
					);
					pdo_insert('tg_billrecord', $bdata);
					pdo_update('tg_order',array('comtype'=>1),array('id'=>$value['id']));
					}
//
			}

				}
					$order = order_update_by_params(array('status' => 3,'gettime'=>time(),'comtype'=>1),array('id' => $orderno));
		if($order){
			wl_json(1);
		}else{
			wl_json(0,'确认收货失败！');
		}
	}else{
		wl_json(0,'缺少订单号');
	}
}
if($op =='judgment_detail'){
	$id = intval($_GPC['id']);
	if($id){
		$order = order_get_by_id($id);
		$goods = goods_get_by_params(" id = {$order['g_id']} ");
		if($order['merchantid']){
			$merchant = merchant_get_by_id($order['merchantid']);
			$order['merchant_name'] = $merchant['name'];
		}else{
			$order['merchant_name'] = $_W['account']['name'];
		}
		$sto=pdo_fetch("select * from".tablename('tg_store')."where id ='{$order['checkstore']}' and uniacid='{$_W['uniacid']}'");
		if($goods['is_hexiao']==1){

			//门店信息
			$storesids = explode(",", $goods['hexiao_id']);
			foreach($storesids as$key=>$value){
				if($value){
					$stores[$key] =  pdo_fetch("select * from".tablename('tg_store')."where id ='{$value}' and uniacid='{$_W['uniacid']}'");
				}
			}
		}
		$sal=pdo_fetch("select * from" . tablename('tg_member') . " where from_user ='".$order['veropenid']."'");
	}
	$iswrite=pdo_fetch("select * from".tablename('tg_judgment')."where orderno ='{$order['orderno']}' ");

	include wl_template('order/judgment_detail');
}
if($op =='judement_submit'){
	$jud_date = $_GPC['jud_date'];
	$si = $_GPC['si'];

	for( $i=0;$i<$si;$i++){

		$openid = $jud_date[$i]['openid'];
		$orderno = $jud_date[$i]['orderno'];
		$gid = $jud_date[$i]['gid'];
		$content = $jud_date[$i]['content'];
		$uniacid = $jud_date[$i]['uniacid'];
		$item = $jud_date[$i]['item'];
		$gname = pdo_fetch("SELECT gname FROM " . tablename('tg_goods') . " WHERE id = " . $gid ."  ");
		$openname = pdo_fetch("SELECT nickname,avatar FROM " . tablename('tg_member') . " WHERE uniacid = " . $uniacid ." and openid =  '". $openid ."' ");

		$data_admin['judgment_id'] =  date('Ymd').substr(time(), -5).substr(microtime(), 2, 5).sprintf('%02d', rand(0, 99));
		$data_admin['gname'] =  $gname['gname'];
		$data_admin['gid'] =  $gid;
		$data_admin['uniacid'] = $uniacid;
		$data_admin['openid'] = $openid;
		$data_admin['openname'] = $openname['nickname'];
		$data_admin['status'] = 0;
		$data_admin['create_time'] = TIMESTAMP;
		$data_admin['update_time'] = TIMESTAMP;
		$data_admin['avatar'] =  $openname['avatar'];
		$data_admin['item'] =  $item;
		$data_admin['orderno'] =  $orderno;

		//评论属性
		$data_admin['iszhuijia'] =  intval($jud_date[$i]['iszhuijia']);
		$data_admin['ishaoyong'] =  intval($jud_date[$i]['ishaoyong']);
		$data_admin['iszhengpin'] =  intval($jud_date[$i]['iszhengpin']);
		$data_admin['ispianyi'] =  intval($jud_date[$i]['ispianyi']);
		$data_admin['iswuliu'] =  intval($jud_date[$i]['iswuliu']);
		$data_admin['iszhiliang'] =  intval($jud_date[$i]['iszhiliang']);
		$data_admin['isfuwu'] =  intval($jud_date[$i]['isfuwu']);
		$data_admin['isqita'] =  intval($jud_date[$i]['isqita']);
		//end

		$addjudgment = pdo_insert('tg_judgment', $data_admin);

		$data_content['judgment_id'] = $data_admin['judgment_id'];
		$data_content['content_id'] =  $data_admin['judgment_id'];
		$data_content['content'] = $content;
		$data_content['update_time'] = TIMESTAMP;
		$data_content['who'] = 0;

		$addjudgment_content = pdo_insert('tg_judgment_content', $data_content);

//		$img_s = $jud_date[$i]['img_s'];
//		$xi = 0;
//		foreach($img_s as $key => $value) {
//			$data2 = array('img_url' => $value, 'content_id' => $data_content['content_id']);
//			pdo_insert('tg_judgment_img', $data2);
//		}
//		$file_base64 = preg_replace('/data:.*;base64,/i', '', $img_s[0]['img']);
//		$img = base64_decode($file_base64);
//		file_put_contents('./tex2t.jpg', $img);
//			$img_url = base64_decode($img_s[0]['img']);
//			$data2 = array('img_url' => $img_url, 'content_id' => $data_content['content_id']);
//			pdo_insert('tg_judgment_img', $data2);


	}
	die(json_encode($xi));
}
//if($op =='judement_img'){
//	$imgs = $_GPC['img'];
//	$uniacid = $_GPC['uniacid'];
//	$id =  date('Ymd').substr(time(), -5).substr(microtime(), 2, 5).sprintf('%02d', rand(0, 99));
//	$file_base64 = preg_replace('/data:.*;base64,/i', '', $imgs);
//	$img = base64_decode($file_base64);
//	file_put_contents('../attachment/images/'.$uniacid.'/'.$id.'.jpg', $img);
//	$img_url='images/'.$uniacid.'/'.$id.'.jpg';
//	die(json_encode($img_url));
//}
if($op =='judement_again'){
	$jud_date = $_GPC['jud_date'];
	$si = $_GPC['si'];

	for( $i=0;$i<$si;$i++){

		$judgment_id = $jud_date[$i]['judgment_id'];
		$content = $jud_date[$i]['content'];

		$data_content['judgment_id'] = $judgment_id;
		$data_content['content_id'] =  date('Ymd').substr(time(), -5).substr(microtime(), 2, 5).sprintf('%02d', rand(0, 99));
		$data_content['content'] = $content;
		$data_content['update_time'] = TIMESTAMP;
		$data_content['who'] = 0;

		$addjudgment_content = pdo_insert('tg_judgment_content', $data_content);

	}
	die(json_encode($judgment_id));
}


if($op =='sng_list'){
    $status = ($_GPC['status']!='')?$_GPC['status']:'';
    $attend = ($_GPC['attend']!='')?$_GPC['attend']:'';

    include wl_template('myorder');
}

if($op =='sng_ajax'){
    $page = $_GPC['page'];
    $pagesize = $_GPC['pagesize'];
    $status = $_GPC['status'];
    $attend = intval($_GPC['attend']);
    $page = !empty($page)? intval($page): 1;
    $pagesize = !empty($pagesize)? intval($pagesize): 10;
    $orderby = " order by id desc";

    $condition = ' and uniacid = :uniacid and openid = :openid';
    if ($status != '') {
        $condition .= " and status in ( " . $status . " )";
    }
    if ($attend != '') {
        $condition .= " and attend = '1' ";
    }

    $uniacid = $_W['uniacid'];
    $openid = $_W['openid'];
//    die(json_encode(array('uniacid' => $uniacid , 'openid' => $openid)));
    $params = array(':uniacid' => $uniacid , 'openid' => $openid);

    $total = pdo_fetchcolumn("SELECT COUNT(*) FROM " .tablename('tg_order')." where 1 $condition ",$params);

    $condition .= $orderby;
    $condition .= " limit " . ($page - 1) * $pagesize . " , " . $pagesize;
    $sql = "SELECT * FROM " .tablename('tg_order')." where 1 $condition  ";
    $list = pdo_fetchall($sql,$params);

    $data = array();
    $data['list'] = $list;
    $data['total'] = $total;
    foreach($data['list'] as $key =>&$value){

        $value['a'] = app_url('order/order/detail',array('id'=>$value['id']));
        $ord=pdo_fetch('select * from '.tablename('tg_order_level_refund').' where status=2 and orderno=:orderno',array(':orderno'=>$value['orderno']));
        $value['refund']=round($ord['refundprice'],2);
        $value['realprice']=round($value['pay_price'],2)-round($ord['refundprice'],2);
        switch($value['status']){
            case 0:$statusname='待付款';break;
            case 1:$statusname='已付款';break;
            case 2:$statusname='待收货';break;
            case 3:$statusname='已完成';break;
            case 4:$statusname='已退款';break;
            case 5:$statusname='强退款';break;
            case 6:$statusname='部分退款';break;
            case 7:$statusname='已退款';break;
            case 8:$statusname='待使用';break;
            case 9:$statusname='已取消';break;
            case 10:$statusname='待退款';break;
            default:$statusname='待付款';
        }
        $createqrcode =  new creat_qrcode();
        $createqrcode->creategroupQrcode($value['orderno']);
        if($value['status']==8&&$value['is_hexiao']!=0){

            $statusname='到店自提';
        }
        if($value['g_id']>0){
            $goods = goods_get_by_params(" id = {$value['g_id']} ");
            $value['gimg'] = $goods['share_image'];
            $value['name'] = $value['goodsname'];
            if(empty($value['name']))
            {
                $value['name']='数据已删除';
            }
            $value['selltype'] = $goods['selltype'];
            if($value['status']==0)
            {
                $count_order=pdo_fetchall('select id from cm_tg_order where tuan_id=:tuan_id and openid=:openid and status in (1,2,3,7,8,10)',array(':tuan_id'=>$value['tuan_id'],':openid'=>$_W['openid']));
                if(!empty($count_order))
                {
                    pdo_update('tg_order',array('status'=>9),array('orderno'=>$vlaue['orderno']));
                    $value['status']=9;
                    $statusname='已取消';
                }

            }
        }else{
            $value['name']=$value['orderno'];
            $value['gimg'] = tomedia($config['share']['share_image']);
            $value['goods']=pdo_fetchall("select * from ".tablename('tg_collect')." where  orderno=:orderno",array('orderno'=>$value['orderno']));
            foreach($value['goods'] as $k =>&$v){
                $gs=pdo_fetch("select * from ".tablename('tg_goods')." where  id=:id",array('id'=>$v['sid']));
                $v['gname']=$v['goodsname'];
            }
        }

        $value['service']=0;
        if($value['status'] == 1 || $value['status'] == 2 || $value['status'] == 3|| $value['status'] == 6|| $value['status'] == 8){
            $value['service']=$config['base']['service'];
        }
        if($value['servestype'] >0)
        {
            $value['service']=$config['base']['service'];
        }
        $value['ga'] = $goods['a'];
        $value['statusname'] = $statusname;
        if($value['status'] != 5 && $value['status'] != 0 && $value['is_tuan'] == 1){
            $value['ta'] = app_url('order/group')."&tuan_id=".$value['tuan_id'];
        }
        $value['sa'] = app_url('order/serves')."&id=".$value['id'];
        if($value['merchantid']){
            $merchant = merchant_get_by_id($value['merchantid']);
            $value['merchant_name'] = $merchant['name'];
        }else{
            $value['merchant_name'] = $_W['account']['name'];
        }
        if($goods['hasoption']==1){
            if ($value['optionid']>0) {
                $option = pdo_fetch("select title,productprice,marketprice,stock,weight from" . tablename("tg_goods_option") . " where id=:id limit 1", array(":id" => $value['optionid']));
            }
            //$value['optionname'] = $option['title'];

        }

        $time = time();
        $end = $value['goods'][0]['endtime'];
        $value['endtime'] = $end;
        $times = pdo_fetch("select * from " .tablename('tg_times') ." where uniacid = :uniacid" , array(":uniacid" => $_W['uniacid']));
        $times = $times['activity'] * 60 * 60;
        if ($end - $times > $time){
            $value['cancel_status'] = true;
//            die(json_encode($value['cancel_status']));
        }else{
            $value['cancel_status'] = false;
        }
        if ($end > 0 && $end < $time && $value['status'] == 8){
            $value['attended'] = 0;
            pdo_update('tg_order',array('attend'=>false),array('orderno'=>$value['orderno']));
            if ($value['black'] == 0){
                pdo_update('tg_order',array('black' => 1),array('orderno'=>$value['orderno']));
            }
            $value['statusname'] = '已失效';
        }
        if ($_W['uniacid'] == 6 || $_W['uniacid'] == 4|| $_W['uniacid'] == 13){
            $value['startTimeStr'] = $value['goods'][0]['starttime'];
            $value['endTimeStr'] = $value['goods'][0]['endtime'];
            $value['startTimeStr'] = date('Y-m-d H:i' , $value['startTimeStr']);
            $value['endTimeStr'] = date('Y-m-d H:i' , $value['endTimeStr']);
        }
    }
    die(json_encode($data));
}

$cs_end_time = time();
//TODO 创建日志
$path = TG_DATA . "/log/" . $_W['uniacid'] . "/debug/";
//首先判断目录存在否
if (!is_dir($path)){
    //第3个参数“true”意思是能创建多级目录，iconv防止中文目录乱码
    $res = mkdir(iconv("UTF-8", "GBK", $path), 0777, true);
}
$date = date('Y-m-d' , TIMESTAMP);
file_put_contents($path.$date.".log", var_export(
        array(
            'ip' => CLIENT_IP ,
            'op' => $op ,
            'filepath' => __FILE__ ,
            'line' => __LINE__ ,
            'start' => date('Y-m-d H:i:s' , $cs_start_time) ,
            'emd' => date('Y-m-d H:i:s' , $cs_end_time)
        ),
        true) .PHP_EOL, FILE_APPEND);
exit();
